package com.yanqu.road.entity.activity.climbtower;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.utils.RandomHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

public class ClimbTowerConfig {

    private ActivityInfo activityInfo;

    private List<ClimbTowerLevelInfo> levelInfoList;

    private List<ClimbTowerTemplateInfo> templateInfoList;

    private List<ClimbTowerRoleInfo> roleInfoList;

    private List<ClimbTowerEventInfo> eventInfoList;

    private List<ClimbTowerMultipleInfo> multipleInfoList;

    private List<ClimbTowerInfo> towerInfoList;

    private int auraMax = 100;
    private int auraGetCd = 180;
    private int auraGetNum = 1;
    private int auraCostNum = 1;
    private int playerStrengthBegin = 5;
    private int drawScoreBase;
    /**
     * 随机其他元素填充的权重
     */
    private List<Integer> drawElementWeight;
    private int addAuraItemId = 120866;
    private int scoreItemId = 101812;
    private List<String> drawSaveList;
    private int expItemId = 120873;
    private int strengthItemId = 120874;
    private int auraItemId = 120875;
    private int drawThreeMultiple = 5;
    private int towerMaxFloor = 1006;

    private List<Integer> armsPicList;
    private List<Integer> ghostIdList;
    private int skillUpnum;

    List<Integer> bossExParamList;
    /**
     * 获取当前层
     * @param passId 阶段
     * @param cell 层
     * @return
     */
    public ClimbTowerCell getCell(int passId, int cell) {
        if(passId <= 0){
            return null;
        }
        if(cell < 0){
            return null;
        }
        for (ClimbTowerLevelInfo levelInfo : levelInfoList) {
            if(levelInfo.getId() != passId){
                continue;
            }
            if(cell >= levelInfo.getCellList().size()){
                return null;
            }
            return levelInfo.getCellList().get(cell);
        }
        return null;
    }

    /**
     * 获取下一层
     * @param passId 阶段
     * @param cell 层
     * @return
     */
    public ClimbTowerCell getNextCell(int passId, int cell) {
        if(passId <= 0){
            return levelInfoList.get(0).getCellList().get(0);
        }
        ClimbTowerLevelInfo next = null;
        for (int i = 0; i < levelInfoList.size(); i++) {
            ClimbTowerLevelInfo levelInfo = levelInfoList.get(i);
            if (levelInfo.getId() != passId) {
                continue;
            }
            if (cell + 1 < levelInfo.getCellList().size()){
                return levelInfo.getCellList().get(cell + 1);
            }
            if (i + 1 < levelInfoList.size()){
                next = levelInfoList.get(i + 1);
            }
            if(next == null){
                return null;
            }
            return next.getCellList().get(0);
        }
        return null;
    }


    public ClimbTowerTemplateInfo getClimbTowerTemplateInfo(List<ClimbTowerTemplateInfo> list, int templateId){
        if(list != null){
            for (ClimbTowerTemplateInfo templateInfo : list) {
                if(templateId == templateInfo.getId()){
                    return templateInfo;
                }
            }
        }
        if(this.templateInfoList != null){
            for (ClimbTowerTemplateInfo templateInfo : this.templateInfoList) {
                if(templateId == templateInfo.getId()){
                    return templateInfo;
                }
            }
        }
        return null;
    }

    /**
     * 根据检验获取角色等级
     * @param exp 经验
     * @return
     */
    public ClimbTowerRoleInfo getClimbTowerRoleInfo(BigInteger exp){
        BigInteger need = BigInteger.ZERO;
        ClimbTowerRoleInfo role = null;
        for (ClimbTowerRoleInfo roleInfo : roleInfoList) {
            role = roleInfo;
            need = need.add(roleInfo.getExp());
            if(exp.compareTo(need) < 0){
                break;
            }
        }
        return role;
    }

    public ClimbTowerLevelInfo getClimbTowerLevelInfo(int passId){
        for (ClimbTowerLevelInfo levelInfo : levelInfoList) {
            if(levelInfo.getId() == passId){
                return levelInfo;
            }
        }
        return null;
    }

    /**
     * 随机老虎机组合(按权重）
     * @return
     */
    public ClimbTowerMultipleInfo randomClimbTowerDrawInfo(){
        List<Integer> weightList = new ArrayList<>();
        for (ClimbTowerMultipleInfo drawInfo : multipleInfoList) {
            weightList.add(drawInfo.getWeight());
        }
        int idx = RandomHelper.getRandomIndexByWeight(weightList);
        return multipleInfoList.get(idx);
    }

    /**
     * 获取老虎机盘面可出现的元素
     * @return
     */
    public List<Integer> getDrawElement(){
        List<Integer> elementList = new ArrayList<>();
        for (ClimbTowerEventInfo eventInfo : eventInfoList) {
            if(eventInfo.getType() == 1){
                elementList.add(eventInfo.getId());
            }
        }
        return elementList;
    }

    public ClimbTowerEventInfo getEventInfoByTypes(int type, int id){
        for (ClimbTowerEventInfo eventInfo : eventInfoList) {
            if(eventInfo.getType() == type && id == eventInfo.getId()){{
                return eventInfo;
            }}
        }
        return null;
    }

    public ClimbTowerMultipleInfo getSaveDrawInfo(int totalTimes) {
        for (String saveInfo : drawSaveList) {
            List<Integer> timesComboList = StringUtils.stringToIntegerList(saveInfo, ";");
            if(timesComboList.get(0) == totalTimes){
                return getClimbTowerMultipleInfo(timesComboList.get(1));
            }
        }
        return null;
    }

    public ClimbTowerInfo getClimbTowerInfo(int id) {
        for (ClimbTowerInfo towerInfo : towerInfoList) {
            if(towerInfo.getId() == id){
                return towerInfo;
            }
        }
        return null;
    }

    public ClimbTowerMultipleInfo getClimbTowerMultipleInfo(int id){
        for (ClimbTowerMultipleInfo multipleInfo : multipleInfoList) {
            if(id == multipleInfo.getId()){
                return multipleInfo;
            }
        }
        return null;
    }

    public ClimbTowerMultipleInfo getClimbTowerMultipleInfo(String param){
        for (ClimbTowerMultipleInfo multipleInfo : multipleInfoList) {
            if(multipleInfo.getParam().equals(param)){
                return multipleInfo;
            }
        }
        return null;
    }

    public ActivityInfo getActivityInfo() {
        return activityInfo;
    }

    public void setActivityInfo(ActivityInfo activityInfo) {
        this.activityInfo = activityInfo;
    }

    public List<ClimbTowerLevelInfo> getLevelInfoList() {
        return levelInfoList;
    }

    public List<ClimbTowerTemplateInfo> getTemplateInfoList() {
        return templateInfoList;
    }

    public List<ClimbTowerRoleInfo> getRoleInfoList() {
        return roleInfoList;
    }

    public void setLevelInfoList(List<ClimbTowerLevelInfo> levelInfoList) {
        this.levelInfoList = levelInfoList;
    }

    public void setTemplateInfoList(List<ClimbTowerTemplateInfo> templateInfoList) {
        this.templateInfoList = templateInfoList;
    }

    public void setRoleInfoList(List<ClimbTowerRoleInfo> roleInfoList) {
        this.roleInfoList = roleInfoList;
    }

    public int getAuraMax() {
        return auraMax;
    }

    public void setAuraMax(int auraMax) {
        this.auraMax = auraMax;
    }

    public int getAuraGetCd() {
        return auraGetCd;
    }

    public void setAuraGetCd(int auraGetCd) {
        this.auraGetCd = auraGetCd;
    }

    public int getAuraGetNum() {
        return auraGetNum;
    }

    public void setAuraGetNum(int auraGetNum) {
        this.auraGetNum = auraGetNum;
    }

    public int getAuraCostNum() {
        return auraCostNum;
    }

    public void setAuraCostNum(int auraCostNum) {
        this.auraCostNum = auraCostNum;
    }

    public int getPlayerStrengthBegin() {
        return playerStrengthBegin;
    }

    public void setPlayerStrengthBegin(int playerStrengthBegin) {
        this.playerStrengthBegin = playerStrengthBegin;
    }

     public int getDrawScoreBase() {
        return drawScoreBase;
    }

    public void setDrawScoreBase(int drawScoreBase) {
        this.drawScoreBase = drawScoreBase;
    }

    public List<Integer> getDrawElementWeight() {
        return drawElementWeight;
    }

    public void setDrawElementWeight(List<Integer> drawElementWeight) {
        this.drawElementWeight = drawElementWeight;
    }

    public List<ClimbTowerEventInfo> getEventInfoList() {
        return eventInfoList;
    }

    public void setEventInfoList(List<ClimbTowerEventInfo> eventInfoList) {
        this.eventInfoList = eventInfoList;
    }

    public List<ClimbTowerMultipleInfo> getMultipleInfoList() {
        return multipleInfoList;
    }

    public void setMultipleInfoList(List<ClimbTowerMultipleInfo> multipleInfoList) {
        this.multipleInfoList = multipleInfoList;
    }

    public int getAddAuraItemId() {
        return addAuraItemId;
    }

    public void setAddAuraItemId(int addAuraItemId) {
        this.addAuraItemId = addAuraItemId;
    }

    public int getScoreItemId() {
        return scoreItemId;
    }

    public void setScoreItemId(int scoreItemId) {
        this.scoreItemId = scoreItemId;
    }

    public List<String> getDrawSaveList() {
        return drawSaveList;
    }

    public void setDrawSaveList(List<String> drawSaveList) {
        this.drawSaveList = drawSaveList;
    }

    public int getExpItemId() {
        return expItemId;
    }

    public void setExpItemId(int expItemId) {
        this.expItemId = expItemId;
    }

    public int getStrengthItemId() {
        return strengthItemId;
    }

    public void setStrengthItemId(int strengthItemId) {
        this.strengthItemId = strengthItemId;
    }

    public int getAuraItemId() {
        return auraItemId;
    }

    public void setAuraItemId(int auraItemId) {
        this.auraItemId = auraItemId;
    }

    public int getDrawThreeMultiple() {
        return drawThreeMultiple;
    }

    public void setDrawThreeMultiple(int drawThreeMultiple) {
        this.drawThreeMultiple = drawThreeMultiple;
    }

    public int getTowerMaxFloor() {
        return towerMaxFloor;
    }

    public void setTowerMaxFloor(int towerMaxFloor) {
        this.towerMaxFloor = towerMaxFloor;
    }

    public List<ClimbTowerInfo> getTowerInfoList() {
        return towerInfoList;
    }

    public void setTowerInfoList(List<ClimbTowerInfo> towerInfoList) {
        this.towerInfoList = towerInfoList;
    }

    public List<Integer> getArmsPicList() {
        return armsPicList;
    }

    public void setArmsPicList(List<Integer> armsPicList) {
        this.armsPicList = armsPicList;
    }

    public List<Integer> getGhostIdList() {
        return ghostIdList;
    }

    public void setGhostIdList(List<Integer> ghostIdList) {
        this.ghostIdList = ghostIdList;
    }

    public int getSkillUpnum() {
        return skillUpnum;
    }

    public void setSkillUpnum(int skillUpnum) {
        this.skillUpnum = skillUpnum;
    }

    public List<Integer> getBossExParamList() {
        return bossExParamList;
    }

    public void setBossExParamList(List<Integer> bossExParamList) {
        this.bossExParamList = bossExParamList;
    }
}
